package nl.windgazer.arachne.pages;

import java.util.HashMap;

import nl.windgazer.arachne.services.facebook.FacebookAPISettings;
import nl.windgazer.arachne.services.facebook.FacebookOpenGraphDAO;
import nl.windgazer.arachne.services.facebook.FacebookOpenGraphException;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.services.PageRenderLinkSource;

public class fbposttest {

	//Injects and Persists

	@Inject
	private FacebookOpenGraphDAO og;

	@Inject
	private FacebookAPISettings settings;

	@Inject
	private ComponentResources resources;

	@Inject
	@Symbol(FacebookAPISettings.APP)
	private String profile;

	@Inject
	private PageRenderLinkSource prls;
	//Properties and Parameters

	@Property(read=true,write=true)
	private String _msg;

	//Components

	@SuppressWarnings("unused")
	@Component(id = "fbpost", parameters = {})
	private Form _fbpostComponent;

	//Events

	@OnEvent(component = "fbpost", value = EventConstants.VALIDATE)
	void methodName() throws FacebookOpenGraphException {
		final HashMap<String, String> values = settings.getSettings();
		final String token = values.get("access_token");
		System.out.println(og.publishFeed("me", token, _msg, null, null, null, null, null, "http://ziffnab.windgazer.nl" + prls.createPageRenderLink( resources.getPageName() ).toAbsoluteURI() ));
		System.out.println(og.readOpenGraph("me", null, token));
	}

	//Other (check for business-logic, it should not remain here)

	public String getToken() {
		return settings.getSettings().get("access_token");
	}

	public String getformAction() {
		return "https://graph.facebook.com/130487793676962/feed";
	}

}
